<script>
    function exprot(){
        alertify.confirm("确定要导出站点数据吗?", function (i) {
            if (i) {
                location.href = "__URL__/export";
            } else {
                alertify.error("取消操作！");
            }
        }, "mcit_default");
    }
</script>
<div>
    <ol class="breadcrumb">
        <li> <i class="fa fa-anchor"></i>
            &nbsp;站点管理
        </li>
        <li>站点列表</li>
        <li style="float:right">
            <a href="javascript:exprot();" class="localRgihtBt"><b>数据导出</b></a>
        </li>
        <li style="float:right"><a href={:U("Site/add")} class="localRgihtBt"><b> 添加站点</b></a></li>
        
        <li style="float:right"><a href={:U("Site/jiucuolist")} class="localRgihtBt"><b> 用户纠错信息列表</b></a></li>
    </ol>
        <div class="panel">
            <div class="panel-heading">
                <i class="fa fa-list">&nbsp;&nbsp;站点信息表</i>
            </div>
        <form class="search-form" action="__ACTION__" method="get" onsubmit="return show_first_page();">
            <div class="panel-body search-panel-body"  >
                <if condition="$_SESSION['role'] eq 808">
                    <div class="col-xs-3 search-col retract">
                        <div class="input-group">
                            <span class="input-group-addon">站点名称</span>
                            <input type="text" name="name" class="form-control" value="{$_GET['name']}"  placeholder="站点名称"></div>
                    </div>
                    <div class="col-xs-2 search-col">
                        <button  type="submit" class="btn btn-warning">
                            <i class="fa fa-search"></i>
                            &nbsp;搜索
                        </button>
                    </div>
                <else />
                    <div class="col-xs-5" style=" width:530px;">
                        <div class="input-group">
                            <span class="input-group-addon" style="width:80px;">所在地</span>
                            <select id="location-f" name="location_f_1" class="form-control" style="width:139px;">
                                <option value="0">--</option>
                                <volist name="china" id="vo">
                                    <option value="{$vo.code}">{$vo.name}</option>
                                </volist>
                            </select>

                            <select id="location-s" name="location_s_1" class="form-control" style="width:125px;border-left:0">
                                <option value="0">--</option>
                                <volist name="china" id="vo">
                                    <volist name="vo['area']" id="vovo">
                                        <option value="{$vovo.code}" class="{$vo.code}" >{$vovo.name}</option>
                                    </volist>
                                </volist>
                            </select>

                            <select id="location-t" name="location_t_1" class="form-control required" style="width:125px;border-left:0">
                                <option value="0">--</option>
                                <volist name="china" id="vo">
                                    <volist name="vo['area']" id="vovo">
                                        <volist name="vovo['area']" id="vovovo">
                                            <option value="{$vovovo.code}" class="{$vovo.code}" >{$vovovo.name}</option>
                                        </volist>
                                    </volist>
                                </volist>
                            </select>
                        </div>
                    </div>
                    <div class="col-xs-3 search-col">
                        <div class="input-group">
                            <span class="input-group-addon">站点名称</span>
                            <input type="text" name="name" class="form-control" value="{$_GET['name']}"  placeholder="站点名称"></div>
                    </div>
                    <div class="col-xs-2 search-col">
                        <button  type="submit" class="btn btn-warning">
                            <i class="fa fa-search"></i>
                            &nbsp;搜索
                        </button>
                    </div>
                </if>
            </div>

            <table  class="table table-bordered table-striped table-mcit" >
                <thead>
                <tr>
                    <th>
                        <button class='btn btn-block btn-mcit'>选择</button>
                    </th>
                    <th >
                        <button class='btn btn-block btn-mcit' type='submit' name='order_name' value=''>站点ID</button>
                    </th>
                    <th>
                        <button class='btn btn-block btn-mcit' type='submit' name='order_stu_num' value=>名称</button>
                    </th>
                    <th>
                        <button class='btn btn-block btn-mcit' type='submit' name='order_idcard' value=>所在地</button>
                    </th>
                    
                    <th>
                        <button class='btn btn-block btn-mcit' type='submit' name='order_plant_mode' value=>运行模式</button>
                    </th>
                    
                    
                   	<th>
                        <button class='btn btn-block btn-mcit' type='submit' name='order_major' value=>类型</button>
                    </th>
                    
                    <th>
                        <button class='btn btn-block btn-mcit' type='submit' name='order_tel' value=''>预约</button>
                    </th>
                    <th>
                        <button class='btn btn-block btn-mcit' type='submit' name='order_tel' value=''>当前状态</button>
                    </th>
                    <th>
                        <button class='btn btn-block btn-mcit' type='submit' name='order_tel' value=''>是否实时</button>
                    </th>
                    <th>
                        <button class='btn btn-block btn-mcit' type='submit' name='order_qq' value=''>电桩/可充</button>
                    </th>
                    <th>
                        <button class='btn btn-block btn-mcit' type='submit' name='order_household' value=''>快/慢</button>
                    </th>
                    <th>
                        <button class='btn btn-block btn-mcit' type='submit' name='order_edit_self' value=''>操作</button>
                    </th>
                </tr>
                </thead>
                <tbody id="DataTableContent">
                <empty name="plant">
                    <td colspan="99" style="text-align:center" class="danger"> <strong><i class="fa fa-meh-o"></i>
                        &nbsp;&nbsp;当前条件下没有数据</strong>
                    </td>
                    <else />
                    <volist name="plant" id="data">
                        <tr class="lists" align="center">
                            <td><input type="checkbox"  value="{$data.id}"/></td>
                            <td>{$data.id}</td>
                            <td><span title="{$data.name}">{$data.name_text}</span></td>
                            <td>{$data.location}</td>
                            
                            <td>
                               <if condition="($data.plant_mode eq 0) OR ($data.plant_mode eq '')"> 线上
 								<else />线下
 					
								</if>
                            </td>
                            
                            
                            <td><if condition="$data.evc_type eq 1">直流<elseif condition="$data.evc_type eq 3" />混合<else />交流</if></td>
                            <td><if condition="$data.booking eq 1">支持<else />不支持</if></td>
                            <td>
                                <if condition="$data.current_state eq 3">
                                    <a class="btn btn-warning btn-xs changehh" data-value="2" data-id="{$data.id}" data-info="确定将该站点状态修改为“安装中”？?">
                                        &nbsp;&nbsp;&nbsp;规划中&nbsp;&nbsp;&nbsp;
                                    </a>
                                <elseif condition="$data.current_state eq 2"/>
                                    <a class="btn btn-warning btn-xs changehh" data-value="1" data-id="{$data.id}" data-info="确定将该站点状态修改为“运营中”？">
                                        &nbsp;&nbsp;&nbsp;安装中&nbsp;&nbsp;&nbsp;
                                    </a>
                                <else />
                                    <a class="btn btn-success btn-xs" data-value="3" data-id="{$data.id}" data-info="确定将该站点状态修改为“规划中”？">
                                        &nbsp;&nbsp;&nbsp;运营中&nbsp;&nbsp;&nbsp;
                                    </a>
                                </if>
                            </td>
                            <td>
                                <if condition="$data.is_active eq 1">
                                    <a class="btn  btn-xs changeA"  data-value="0" data-id="{$data.id}" data-info="确定修改为“不支持实时”？">
                                        <img src="__PUBLIC__/img/gou.png" alt="是"/>
                                    </a>
                                <else />
                                    <a class="btn  btn-xs changeA" data-value="1" data-id="{$data.id}" data-info="确定修改为“支持实时”？">
                                        <img src="__PUBLIC__/img/cha.png" alt="否"/>
                                    </a>
                                </if>
                            </td>
                            <td>{$data.total_ev}/{$data.total_par}</td>
                            <td>
                                <if condition="$data.charge_fast_num eq '' and $data.charge_slow_num eq ''"><else />
                                    {$data.charge_fast_num}/{$data.charge_slow_num}
                                </if>
                            </td>
                            <td>
                                <a class="btn btn-success btn-sm" href="__URL__/detail/id/{$data.id}">
                                    <i class="fa fa-eye"></i>
                                &nbsp;查看
                                </a>
                                    <a class="btn btn-success btn-sm" href="__APP__/Evcharger/add/id/{$data.id}">
                                        <i class="fa fa-edit"></i>
                                        &nbsp;添加电桩
                                    </a>
                                    <a class="btn btn-warning btn-sm" href="__URL__/update/id/{$data.id}">
                                    <i class="fa fa-edit"></i>
                                    &nbsp;修改
                                    </a>
                                <if condition="$_SESSION['role'] eq 805 or $_SESSION['role'] eq 802">
                                    <a class="btn btn-sm btn-danger deleteBtn" href="#confirmDelete" data-target="#confirmDelete" data-toggle="modal" data-id='{$data.id}'><i class="fa fa-trash-o"></i>
                                        &nbsp;删除</a>
                                <else /></if>
                            </td>
                        </tr>
                    </volist>
                </empty>
                <tr>
                    <td colspan="99">
                        <input type="button" value="全选"   class="btn" id="selectAll">
                        <input type="button" value="全不选" class="btn" id="unSelect">
                        <input type="button" value="反选"   class="btn" id="reverse">
                        <input type="button" value="批量删除" class="btn" id="getValues">
                    </td>
                </tr>
                <tr>
                    <td colspan="99" style="text-align:center">
                        <ul class="pagination">{$pageView}</ul>
                    </td>
                </tr>
                </tbody>
            </table>
            <input type="hidden" name="fsign" id="fsign" value="normal">
        </form>
        </div>
</div>
<!-- 删除分类 -->
<div id="confirmDelete" class="modal  fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
     aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 id="myModalLabel">是否确认删除？</h4>
            </div>
            <div class="modal-body" style="color: #D2322D">
                注意！此站点下所有电桩都将删除，删除后将不可恢复。
            </div>
            <div class="modal-footer">
                <a class="btn" data-dismiss="modal" aria-hidden="true" id="modelClose">关闭</a>
                <a class="btn btn-primary" id="confirmDeleteBtn">确定</a>
            </div>
        </div></div>
    <div class="hide" id="cache">1</div>
</div>
<import file="js.jquery#chained" />
<script type="text/javascript">
    function show_first_page(){
        $("#fsign").val("abnormal");
        return true;
    }

        $(document).ready(function () {
        $("#location-s").chained("#location-f");
        $("#location-t").chained("#location-s");

        $(".deleteBtn").click(function (){
            var id = $(this).attr("data-id");
            $("#cache").val(id);
        });
        $("#confirmDeleteBtn").click(function (){
            var id = $("#cache").val();
            $.ajax({
                type:"get",
                url:'__URL__/del',
                data:'id='+id,
                success:function(data){
                    if(data == 1){
                        alertify.success("删除成功！");
                    }else{
                        alertify.error("删除失败，请重新提交！");
                    }
                    location.reload();
                }
            });
        });

        $(document).on("click",'.changehh',function(){
            var obj = $(this).parent();
            var id  = $(this).attr("data-id");
            var info = $(this).attr("data-info");
            var value = $(this).attr("data-value");
            alertify.confirm(info, function (e) {
                if (e) {
                    $.ajax({
                        type: "POST",
                        url:  '{:U("Site/changehh")}',
                        data: {id:id,value:value},
                        dataType: "json",
                        success: function(data){
                            if(data.state==100){
                                obj.html(data.html);
                                alertify.success(data.msg);
                            }else if(data.state==200){
                                obj.html(data.html);
                                alertify.success(data.msg);
                            }else if(data.state==300){
                                obj.html(data.html);
                                alertify.success(data.msg);
                            }else{
                                alertify.error(data.msg);
                            }
                            //location.reload();
                        }
                    });
                } else {
                    alertify.error("取消操作！");
                }
            }, "mcit_default");
        });
        $(document).on("click",'.changeA',function(){
            var aobj = $(this).parent();
            var aid  = $(this).attr("data-id");
            var ainfo = $(this).attr("data-info");
            var avalue = $(this).attr("data-value");
            alertify.confirm(ainfo, function (i) {
                if (i) {
                    $.ajax({
                        type: "POST",
                        url:  '{:U("Site/changeA")}',
                        data: {aid:aid,avalue:avalue},
                        dataType: "json",
                        success: function(data){
                            if(data.state==100){
                                aobj.html(data.html);
                                alertify.success(data.msg);
                                //location.reload();
                            }else{
                                alertify.error(data.msg);
                            }
                        }
                    });
                } else {
                    alertify.error("取消操作！");
                }
            }, "mcit_default");
        });

        //全选
        $("#selectAll").click(function () {
            $(".lists :checkbox").prop("checked", true);
        });
        //全不选
        $("#unSelect").click(function () {
            $(".lists :checkbox").prop("checked", false);
        });
        //反选
        $("#reverse").click(function () {
            $(".lists :checkbox").each(function () {
                $(this).prop("checked", !$(this).prop("checked"));
            });
        });
            //批量删除
            $("#getValues").click(function(){
                var valArray = new Array;
                $("input[type='checkbox']:checked").prop("checked", function(i) {
                    valArray[i] = $(this).val();
                });
                var values = valArray.join(',');
                if(values == ''){
                    alert("请选择要处理的数据!");
                }else{
                    //alert(values);
                    alertify.confirm("确定删除吗？", function (e) {
                        if (e) {
                            $.ajax({
                                type: "POST",
                                url:  '{:U("Site/del")}',
                                data: {ids:values},
                                dataType: "json",
                                success: function(data){
                                    if(data.state==100){
                                        alertify.success(data.msg);
                                    }else{
                                        alertify.error(data.msg);
                                    }
                                    location.reload();
                                }
                            });
                        } else {
                            alertify.error("取消操作！");
                        }
                    }, "mcit_default");
                }
            });
    })
</script>